/*
 * the purpose of this class is to test if the classes
 * developped to manipulate a Log are correct and if the
 * XML is well written
 */

package model_package;

import java.util.ArrayList;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import longprojectihm.Tree;

/**
 *
 * @author haythem
 */
public class TestXML {
    public static void main(String[] args) {
//        test of the xml writing (test 1)
        // creation of an Log object
        Date d = new Date(8,10,10,10,10);
        ArrayList<String> listReceivers = new ArrayList<String>();
        listReceivers.add("Angel");
        listReceivers.add("Jiango");
        listReceivers.add("ferzf");
        listReceivers.add("yjtj");
        Log l = new Log("LogTest1");
        Case c = new Case("CaseTest1");
        Event e = new Event("EventTest1", "A", "Haythem", listReceivers, "Demande","co1", d);
        c.addEvent(e);

        Date d1 = new Date(1,10,10,10,10);
        ArrayList<String> listReceivers1 = new ArrayList<String>();
        listReceivers1.add("Angel");
        listReceivers1.add("Jiango");
        Event e1 = new Event("EventTest2", "B", "Haythem", listReceivers1, "Soumettre","co1", d1);
        c.addEvent(e1);

        l.addCase(c);


        Date d2 = new Date(5,10,10,10,10);
        ArrayList<String> listReceivers2 = new ArrayList<String>();
        listReceivers2.add("Angel");
        listReceivers2.add("ferzf");
        listReceivers2.add("yjtj");
        Case c1 = new Case("CaseTest2");
        Event e3 = new Event("EventTest3", "C", "Haythem", listReceivers2, "Tester","co1", d2);
        c1.addEvent(e3);

        l.addCase(c1);

        // fusion test
        l.editCaseID("CaseTest2", "CaseTest1");

        // creation of the XML Test
        l.toString("dd.xml");

//        listReceivers.remove((String) "Angel");
//        listReceivers.remove((String) "Jiango");
//        for (int i=0;i<listReceivers.size();i++){
//            System.out.println(listReceivers.get(i));
//        }

//        end test1


        // test 2
        // test of the arraylist manipulation
//        ArrayList<Integer> l1 = new ArrayList<Integer>();
//        ArrayList<Integer> l2 = new ArrayList<Integer>();
//        ArrayList<Integer> l3 = new ArrayList<Integer>();
//        for (int i=0;i<=5;i++){
//            l1.add(i);
//        }
//        for (int i=6;i<=10;i++){
//            l2.add(i);
//        }
        //    1
//        l3.addAll(l1);
//        l3.addAll(l2);
//        l3.remove(1);
//        l3.remove(8);
        //    2
//        l1.add(l2.get(0));
//        l2.remove(0);
//        System.out.println(" l3 ");
//        for(int i=0;i<l3.size();i++){
//            System.out.println(l3.get(i));
//        }

//        System.out.println(" l2 ");
//        for(int i=0;i<l2.size();i++){
//            System.out.println(l2.get(i));
//        }
//
//        System.out.println(" l1 ");
//        for(int i=0;i<l1.size();i++){
//            System.out.println(l1.get(i));
//        }

       // test2 finished : no effect to delete element from l3 in l2 and l1


        // test 3

//        int i = 3 ;
//        System.out.println(" i1 : "+i);
//        int j = i;
//        i++;
//
//        System.out.println(" j : "+j);
//        System.out.println(" i : "+i);

        // test 3 finished

        

        // test 4
        // tree associated to a Log creation-test
        JFrame fenetre = new JFrame();
        fenetre.setSize(300, 300);
	fenetre.setLocationRelativeTo(null);
	fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	fenetre.setTitle("Les arbres");
		//On invoque la méthode de construction de notre arbre
	final Tree arbre = Tree.buildTree(l);

        // if we want to hide the root ie
        // the log's ID just uncomment the next
        // line
        //arbre.setRootVisible(false);

        // ajout d'un listener
        arbre.addTreeSelectionListener(new TreeSelectionListener(){

			public void valueChanged(TreeSelectionEvent event) {
				if(arbre.getLastSelectedPathComponent() != null){
					System.out.println(arbre.getLastSelectedPathComponent().toString());
				}
			}
		});

        fenetre.getContentPane().add(new JScrollPane(arbre));

        fenetre.setVisible(true);
        
    }
}
